home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-30 | 8.3 KB | 415 lines | [TEXT/CWIE] |
- { MainWindow.p }
- { Created 10/30/98 12:58 PM by AppMaker }
-
- Unit MainWindow;
- Interface
-
- Uses
- Types,
- Quickdraw,
- Controls,
- Dialogs,
- Events,
- Lists,
- Menus,
- Resources,
- TextEdit,
- ToolUtils,
-
- DDocData,
- TemperatureEngine,
- TemperatureDoc,
- AMWindow;
-
- type
- MainWindow = object (AMWindow)
-
- {data members}
- mData: DDocData;
- mCentigradeLabel: ControlHandle;
- mEditCentigradeHandle: ControlHandle;
- mFahrenheitLabel: ControlHandle;
- mEditFahrenheitHandle: ControlHandle;
- mCentSliderHandle: ControlHandle;
- mFahrBarHandle: ControlHandle;
-
- {methods}
- Procedure Initialize; Override;
-
- Procedure Open (inDoc: TemperatureDoc;
- inData: DDocData);
- Procedure Close; Override;
-
- Procedure Control (whichControl: ControlHandle;
- whichPart: integer;
- where: Point); Override;
- Procedure MouseIn (where: Point;
- modifiers: integer); Override;
- Procedure TypeIn (charCode: SInt16); Override;
- Procedure ExitCurField; Override;
- Procedure DataChanged (inDataID: longint); Override;
- Procedure Resize; Override;
- Procedure Scroll (newValue: integer;
- oldValue: integer); Override;
-
- Function GetEngine: TemperatureEngine;
-
- {$ifc false}
- Procedure UpdateMenus; Override;
- {$endif}
- Function DoCommand (inCommand: longint): Boolean; Override;
-
- Procedure DoUndo;
- Procedure DoCut;
- Procedure DoCopy;
- Procedure DoPaste;
- Procedure DoClear;
- Procedure DoSelectAll;
- Procedure DoShowClipboard;
-
- end;
-
- {----------}
- Procedure CreateMainWindow (inDoc: TemperatureDoc;
- inData: DDocData);
-
- {----------}
- Implementation
-
- Uses
- Globals,
- ResourceDefs,
- DoScrap,
- Scrolling,
- ControlUtils,
- Miscellany;
-
- const
- kCentigradeLabel = 1;
- kEditCentigradeField = 2;
- kFahrenheitLabel = 3;
- kEditFahrenheitField = 4;
- kCentSliderScroll = 5;
- kFahrBarBar = 6;
-
- {----------}
- Procedure CreateMainWindow (
- inDoc: TemperatureDoc;
- inData: DDocData);
- var
- winObj: MainWindow;
- begin
- winObj := nil;
- New (winObj);
-
- if winObj <> nil then begin
- winObj.Initialize;
- winObj.Open (inDoc, inData);
- end;
- end;
-
- {----------}
- Procedure MainWindow.Initialize;
- begin
- Inherited Initialize;
- end;
-
- {----------}
- Function MainWindow.GetEngine: TemperatureEngine;
- begin
- GetEngine := TemperatureEngine (mDoc.mEngine);
- end;
-
- {----------}
- Procedure MainWindow.Open (
- inDoc: TemperatureDoc;
- inData: DDocData);
- var
- window: WindowPtr;
- wftb: Handle;
- errCode: OSErr;
- begin
- mDoc := inDoc;
- mData := inData;
- mData.AddResponder (self);
-
- window := GetNewCWindow (WIND_MainWindow, nil, WindowPtr (-1));
- if inDoc.mEngine.GetFilename <> '' then begin
- SetWTitle (window, inDoc.mEngine.GetFilename);
- end;
- mWindow := window;
- TemperatureDoc (mDoc).mMainWindowPtr := window;
-
- WindowPeek (window)^.windowKind := kAMWindowFlag;
- SetWRefCon (window, ord4 (self));
- SetPort (window);
- SetInfo (window);
-
- wftb := GetResource ('Wftb', WIND_MainWindow);
-
- errCode := CreateRootControl (window, mRootControl);
-
- vScroll := nil;
- hScroll := nil;
-
-
- mCentigradeLabel := GetNewControl (CNTL_Centigrade, window);
- SetWindowItemFont (mCentigradeLabel, wftb, 1);
- SetControlFromTEXT (mCentigradeLabel, TEXT_Centigrade);
-
- mEditCentigradeHandle := GetNewControl (CNTL_EditCentigrade, window);
- SetWindowItemFont (mEditCentigradeHandle, wftb, 2);
- SetControlTextValue (mEditCentigradeHandle, mData.GetCentigrade);
-
- mFahrenheitLabel := GetNewControl (CNTL_Fahrenheit, window);
- SetWindowItemFont (mFahrenheitLabel, wftb, 3);
- SetControlFromTEXT (mFahrenheitLabel, TEXT_Fahrenheit);
-
- mEditFahrenheitHandle := GetNewControl (CNTL_EditFahrenheit, window);
- SetWindowItemFont (mEditFahrenheitHandle, wftb, 4);
- SetControlTextValue (mEditFahrenheitHandle, mData.GetFahrenheit);
-
- mCentSliderHandle := GetNewControl (CNTL_CentSlider, window);
- SetWindowItemFont (mCentSliderHandle, wftb, 5);
- SetControlValue (mCentSliderHandle, mData.GetCentigrade);
-
- mFahrBarHandle := GetNewControl (CNTL_FahrBar, window);
- SetWindowItemFont (mFahrBarHandle, wftb, 6);
- SetControlValue (mFahrBarHandle, mData.GetFahrenheit);
-
- errCode := AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- end;
-
- {----------}
- Procedure MainWindow.Close;
- begin
- mData.RemoveResponder (self);
-
- TemperatureDoc (mDoc).mMainWindowPtr := nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- Dispose (self);
- end;
-
- {----------}
- Procedure MainWindow.Control (
- whichControl: ControlHandle;
- whichPart: integer;
- where: Point);
- var
- bounds: Rect;
- newValue: integer;
- partcode: SInt16;
- begin
- ExitCurField ();
-
- if whichControl = mEditCentigradeHandle then begin
- HandleEditClick (mEditCentigradeHandle, where);
- end;
- if whichControl = mEditFahrenheitHandle then begin
- HandleEditClick (mEditFahrenheitHandle, where);
- end;
- if whichControl = mCentSliderHandle then begin
- partCode := HandleControlClick (mCentSliderHandle, where, curEvent.modifiers, nil);
- mData.SetCentigrade (GetControlValue (mCentSliderHandle));
- end;
- end;
-
- {----------}
- Procedure MainWindow.DataChanged (
- inDataID: longint);
- begin
- if inDataID = idCentigrade then begin
- SetControlTextValue (mEditCentigradeHandle, mData.GetCentigrade);
- end;
- if inDataID = idFahrenheit then begin
- SetControlTextValue (mEditFahrenheitHandle, mData.GetFahrenheit);
- end;
- if inDataID = idCentigrade then begin
- SetControlValue (mCentSliderHandle, mData.GetCentigrade);
- end;
- if inDataID = idFahrenheit then begin
- SetControlValue (mFahrBarHandle, mData.GetFahrenheit);
- end;
- End;
-
- {----------}
- Procedure MainWindow.MouseIn (
- where: Point;
- modifiers: integer);
- var
- bounds: Rect;
- begin
- end;
-
- {----------}
- Procedure MainWindow.ExitCurField;
- var
- errCode: OSErr;
- focus: ControlHandle;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- if focus = nil then begin
- { nothing to exit }
-
- end else if focus = mEditCentigradeHandle then begin
- mData.SetCentigrade (GetControlTextValue (mEditCentigradeHandle));
- end else if focus = mEditFahrenheitHandle then begin
- mData.SetFahrenheit (GetControlTextValue (mEditFahrenheitHandle));
- end;
- inherited ExitCurField;
- end;
-
- {----------}
- Procedure MainWindow.TypeIn (
- charCode: SInt16);
- var
- ch: char;
- errCode: OSErr;
- focus: ControlHandle;
- keyCode: SInt16;
- partcode: SInt16;
- begin
- errCode := GetKeyboardFocus (mWindow, focus);
-
- ch := chr (charCode);
- if (ch = charEnter)
- | (ch = charReturn) then begin
- ExitCurField;
- end else if ch = charEsc then begin
- end else if ch = charTab then begin
- DoTab (BAnd (curEvent.modifiers, optionKey) <> 0);
- end else if focus <> nil then begin
- keyCode := BAnd (curEvent.message, keyCodeMask);
- partcode := HandleControlKey (focus, keyCode, charCode, curEvent.modifiers);
- mDoc.mEngine.SetDirty;
- end else begin
- SysBeep (1);
- end;
- end;
-
- {----------}
- Procedure MainWindow.Resize;
- begin
- { application-specific code to resize items in window }
- end;
-
- {----------}
- Procedure MainWindow.Scroll (
- newValue: integer;
- oldValue: integer);
- begin
- { application-specific code to scroll window }
- if gWhichScroll = vScroll then begin
- end else begin { horizontal }
- end;
- end;
-
- {----------}
- Procedure MainWindow.DoUndo;
- begin
- end; {DoUndo}
-
- {----------}
- Procedure MainWindow.DoCut;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECut (curTE);
- mDoc.mEngine.SetDirty;
- scrapDirty := true;
- end;
- end; {DoCut}
-
- {----------}
- Procedure MainWindow.DoCopy;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TECopy (curTE);
- scrapDirty := true;
- end;
- end; {DoCopy}
-
- {----------}
- Procedure MainWindow.DoPaste;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEPaste (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoPaste}
-
- {----------}
- Procedure MainWindow.DoClear;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TEDelete (curTE);
- mDoc.mEngine.SetDirty;
- end;
- end; {DoClear}
-
- {----------}
- Procedure MainWindow.DoSelectAll;
- var
- curTE: TEHandle;
- begin
- curTE := GetCurTE ();
-
- if curTE <> nil then begin
- TESetSelect (0, 32767, curTE);
- end;
- end; {DoSelectAll}
-
- {----------}
- Procedure MainWindow.DoShowClipboard;
- begin
- end; {DoShowClipboard}
-
- {----------}
- Function MainWindow.DoCommand (
- inCommand: longint): Boolean;
- begin
- DoCommand := true;
- case inCommand of
- cmdUndo:
- DoUndo;
- cmdCut:
- DoCut;
- cmdCopy:
- DoCopy;
- cmdPaste:
- DoPaste;
- cmdClear:
- DoClear;
- cmdSelectAll:
- DoSelectAll;
- cmdShowClipboard:
- DoShowClipboard;
-
- otherwise
- DoCommand := false;
- end; {case}
- end;
-
- end.
-